
import { request } from '../request';

/** 角色管理*/
export function fetchGetRoleList(params?: Api.SystemManage.RoleSearchParams) {
  return request<Api.SystemManage.RoleList>({
    url: '/systemManage/getRoleList',
    method: 'get',
    params
  });
}

// 根据角色ID查询权限ID /////////////////////////////////////////////////////////////////////////////
export function queryPermissionIdsWithRoleId(roleId: number) {
  return request<number[]>({
    url: `/systemManage/permission/${roleId}`,
    method: 'get'
  });
}


/** 角色添加 修改*/
export function fetchGetRoleInsert(params?: Api.SystemManage.RoleSearchParams) {
  return request<Api.SystemManage.RoleList>({
    url: '/systemManage/addRole',
    method: 'post',
    data: params
  });
}

/** 角色删除*/
export function fetchGetRoleRemove(id:number) {
  return request({
    url: `/systemManage/remove/${id}`,
    method: 'delete'
  });
}

/** 查询角色资源ID*/
export function getRoleResourceId(id: number) {
  return request({
    url: '/systemManage/getRoleResourceId',
    method: 'post',
    params: { roleId: id } // 通过URL查询字符串传递
  });
}

/** 修改角色资源信息*/
export function updateRoleResourceInfo(params?: Api.SystemManage.RoleParamParams) {
  return request({
    url: '/systemManage/updateRoleResourceInfo',
    method: 'post',
    data: params
  });
}


/**
 * get all roles
 *
 * these roles are all enabled
 */
export function fetchGetAllRoles() {
  return request<Api.SystemManage.AllRole[]>({
    url: '/systemManage/getAllRoles',
    method: 'get'
  });
}

// 菜单权限列表
export function queryMenuPermission() {
  return request<Api.SystemManage.SysMenuPermission>({
    url: '/systemManage/permission',
    method: 'get'
  });
}

// 更新角色权限管理信息
export function add(params?: Api.SystemManage.SysRolePermissionUpdateDTO) {
 console.log(params);
  return request({
    url: '/systemManage',
    method: 'post',
    data: params
  });
}

/** 查询用户列表 */
export function fetchGetUserList(params?: Api.SystemManage.UserSearchParams) {
  return request<Api.SystemManage.UserList>({
    url: '/systemManage/getUserList',
    method: 'get',
    params
  });
}

/** 修改用户 */
export function updateUser(params?: Api.SystemManage.UserSearchParams) {
  return request({
    url: '/systemManage/update',
    method: 'post',
    data: params
  });
}

export function resetPassword(params: any) {
  console.log(params);
  return request({
    url: '/auth/resetPassword',
    method: 'get',
    params: params
  });
}


/** 新增用户 */
export function createUser(params?: Api.SystemManage.UserSearchParams) {
  return request({
    url: '/systemManage/createUser',
    method: 'post',
    data: params
  });
}

/** 批量&删除用户 */
export function removeByIdList(roleId: number[]) {  
  return request({
    url: "/systemManage/removeById",
    method: 'post',
    data: roleId
  });
}

/** get menu list */
export function fetchGetMenuList() {
  return request<Api.SystemManage.MenuList>({
    url: '/systemManage/getMenuList/v2',
    method: 'get'
  });
}

/**
 * 
 * @param params 新增菜单页面
 * @returns 
 */
export function fetchGetMenuListadd(params?: Api.SystemManage.MenuPropsOfMenu) {
  return request<Api.SystemManage.MenuList>({
    url: '/sys/resource/add',
    method: 'post',
    data:params
  });
}

/** 批量&删除菜单 */
export function fetchGetMenuRemoveById(id: number) {
  return request({
    url: `/sys/resource/removeById/${id}`,
    method: 'delete'
  });
}



/** get all pages */
export function fetchGetAllPages() {
  return request<string[]>({
    url: '/systemManage/getAllPages',
    method: 'get'
  });
}

/** get menu tree */
export function fetchGetMenuTree() {
  return request<Api.SystemManage.MenuTree[]>({
    url: '/systemManage/getMenuTree',
    method: 'get'
  });
}

/**
 * 上传图标
 * @param fileUploadDto 包含文件和路径信息的对象
 */
export function uploadIcon(fileUploadDto: {
  file: File;
  imageName: string;
  jImageName?: string;
}) {
  const formData = new FormData();
  formData.append('file', fileUploadDto.file);
  formData.append('imageName', fileUploadDto.imageName);
  if (fileUploadDto.jImageName) {
    formData.append('jImageName', fileUploadDto.jImageName);
  }  
  return request({
    url: '/admin/system/icon',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

/**
 * 删除图标
 * @param params 包含路径信息和文件名的对象
 */
export function deleteIcon(params: {
  imageName: string;
  jImageName: string;
}) {
  return request({
    url: '/admin/system/deleteIcon',
    method: 'delete',
    params
  });
}
